package com.jeecms.wicool.manager.user.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.user.ScoreTradeDao;
import com.jeecms.wicool.entity.user.ScoreTrade;
import com.jeecms.wicool.entity.user.UserInfo;
import com.jeecms.wicool.manager.user.ScoreTradeMng;
import com.jeecms.wicool.manager.user.UserInfoMng;

@Service
@Transactional
public class ScoreTradeMngImpl implements ScoreTradeMng {
	
	private ScoreTradeDao dao;
	@Autowired
	public void setDao(ScoreTradeDao dao) {
		this.dao = dao;
	}
	
	@Transactional(readOnly = true)
	public Pagination getPage(Integer userId,String userName,int pageNo, int pageSize) {
		Pagination page = dao.getPage( userId,userName, pageNo, pageSize);
		return page;
	}
	@Override
	public ScoreTrade findById(Integer id) {
		ScoreTrade entity = dao.findById(id);
		return entity;
	}
	@Override
	public ScoreTrade update(ScoreTrade bean,Integer userId) {
		UserInfo user= userMng.findById(userId);
		bean.setUser(user);
		Updater<ScoreTrade> updater = new Updater<ScoreTrade>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}
	
	@Override
	public ScoreTrade save(ScoreTrade bean,Integer userId) {
		
		UserInfo user = userMng.findById(userId);
		bean.setUser(user);
		dao.save(bean);
		return bean;
	}

	@Override
	public ScoreTrade deleteById(Integer id) {
		ScoreTrade bean = dao.deleteById(id);
		return bean;
	}
	@Override
	public ScoreTrade[] deleteByIds(Integer[] ids) {
		ScoreTrade[] beans = new ScoreTrade[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}
	@Override
	public List<ScoreTrade> getListScoreTradeByUserId(Integer userId) {
		// TODO Auto-generated method stub
		return dao.getListScoreTradeByUserId(userId);
	}
	@Autowired
	private UserInfoMng userMng;
	
}